//
//  LXClientDetailView.m
//  跑跑快销
//
//  Created by linxian on 14-4-29.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "LXClientDetailView.h"

@implementation LXClientDetailView
@synthesize  cdTableView, funcView, clientName, LeftBtn, RightBtn, LeftImgView, RightImgView;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self drawUIView];
    }
    return self;
}

- (void)drawUIView
{
    [self createViewDown];
    [self createViewUp];
    [self createHeadView];
    [self createFootView];
}

- (void)createHeadView
{
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, titleH)];
    clientName = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 310, titleH - 10)];
    clientName.backgroundColor = [UIColor clearColor];
    headView.backgroundColor = [UIColor grayColor];
    [headView addSubview:clientName];
    cdTableView.tableHeaderView = headView;
    _headView = headView;
}

- (void)createFootView
{
    UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, buttonH)];
    // 修复位置按钮
    LeftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 159, buttonH)];
    LeftBtn.backgroundColor = [UIColor blackColor];
    [LeftBtn setTitle:@"修复位置" forState:UIControlStateNormal];
    [footView addSubview:LeftBtn];
    LeftImgView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 30, 30)];
    LeftImgView.contentMode = UIViewContentModeScaleAspectFit;
    LeftImgView.image = [UIImage imageNamed:@"a.png"];
    [LeftBtn addSubview:LeftImgView];
    
    // 删除网点按钮
    RightBtn = [[UIButton alloc] initWithFrame:CGRectMake(160, 0, 159, buttonH)];
    RightBtn.backgroundColor = [UIColor blackColor];
    [RightBtn setTitle:@"删除网点" forState:UIControlStateNormal];
    [RightBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [footView addSubview:RightBtn];
    RightImgView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 30, 30)];
    RightImgView.contentMode = UIViewContentModeScaleAspectFit;
    RightImgView.image = [UIImage imageNamed:@"a.png"];
    [RightBtn addSubview:RightImgView];
    
    cdTableView.tableFooterView = footView;
    _footView = footView;
}

- (void)createViewDown
{
    cdTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320,  buttonH * 6 + titleH+49)];
    cdTableView.showsVerticalScrollIndicator = NO;
    cdTableView.scrollEnabled = NO;
    cdTableView.backgroundColor = [UIColor clearColor];
    [self addSubview:cdTableView];
    
}

- (void)createViewUp
{
    int navBarY,navBarH;
    
    if (ISDEVICE7) {
        navBarY = 0;
        navBarH = 64;
    }else{
        navBarY = 20;
        navBarH = 44;
    }

    funcView = [[UIView alloc] initWithFrame:CGRectMake(0,  buttonH * 6 + titleH, 320, ViewHeight-navBarY)];
    funcView.backgroundColor = [UIColor grayColor];
    for (int i=0; i<NumOfButtons; i++) {
        int section = i / NumOfSection ;
        int row = i % NumOfSection ;
        CGFloat interSpace = (320 - NumOfSection * ButtonW)/4.0f;
        CGFloat width = interSpace + ButtonW ;
        TNButton *btn = [[TNButton alloc] initWithFrame:CGRectMake( interSpace + row * width, ButtonW / 2.0f + section * ButtonH, ButtonW, ButtonH)];
        btn.backgroundColor = [UIColor clearColor];
        btn.tag = i+1;
        [funcView addSubview:btn];
    }
    
    [self addSubview:funcView];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
